<template>
  <div class="overview-content">
    <el-row :gutter="32">
      <el-col :xs="24" :sm="24" :lg="24" style="margin-bottom: 20px">
        <div class="chart-wrapper">
          <div class="divUl">
            <div class="titleDiv">
              {{ detailData.address }} ｜ {{ detailData.leaseNo }}
              <span>[{{ leaseStatusOptions[detailData.status] }}]</span>
            </div>
            <div class="flex-row jus two">
              <p class="countFsColor" @click="goBack">返回</p>
              <p
                v-if="detailData.step <= 3"
                class="countFsColor"
                @click="objMo.show = true"
              >
                中止流程
              </p>
            </div>
            <div class="inputTop">
              <varcla-tab
                :table-data="stepArr"
                :truth-step="detailData.step - 1"
                :active="active"
                @changeActive="(index) => (active = index)"
              />

              <!-- <div>{{ detailData.step - 1 }}{{ active }}</div> -->
              <div class="formdiv">
                <Step1
                  v-if="active == 0"
                  :id="id"
                  :is-edit="detailData.step - 1 != active"
                  @jump="jump"
                  @next="next"
                />
                <Step2
                  v-if="active == 1"
                  :id="id"
                  :is-edit="detailData.step - 1 != active"
                  @jump="jump"
                  @next="next"
                />
                <Step3
                  v-if="active == 2"
                  :id="id"
                  :is-edit="detailData.step - 1 != active"
                  @jump="jump"
                  @next="next"
                />
                <Step4
                  v-if="active == 3"
                  :id.sync="id"
                  :is-edit="detailData.step - 1 != active"
                  @jump="jump"
                  @next="next"
                  @changeId="changeId"
                />
                <StepRenewl
                  v-if="active > 3"
                  :id="id"
                  :active="active"
                  :is-edit="detailData.step - 1 != active"
                  @jump="jump"
                  @next="next"
                />
              </div>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <!--跳过-->
    <myModal :obj="objFour" @save="confirmJump">
      <div class="mpdalBody">
        <el-input
          v-model="jumpData.jumpNote"
          type="textarea"
          placeholder="请输入内容"
          maxlength="200"
          show-word-limit
        />
      </div>
    </myModal>
    <myModal :obj="objMo" @close="objMo.show = false" @save="confirmDel">
      <div class="mpdalBody">
        <p>确认终止？</p>
      </div>
    </myModal>
  </div>
</template>

<script>
import VarclaTab from "./varclaTab.vue";
import myModal from "@/components/Modal";
import { leaseDetail, leaseDel, jump, edit } from "@/api/lease";
import { leaseStatusOptions } from "@/utils/consts";
import Step1 from "./step/step1.vue";
import Step2 from "./step/step2.vue";
import Step3 from "./step/step3.vue";
import Step4 from "./step/step4.vue";
import StepRenewl from "./step/stepRenewl.vue";
export default {
  components: {
    VarclaTab,
    myModal,
    Step1,
    Step2,
    Step3,
    Step4,
    StepRenewl,
  },
  data() {
    return {
      id: "",
      jumpData: {
        jumpNote: "",
        jumpStep: "",
        id: "",
      },
      objMo: {
        show: false,
        title: null,
        width: "300px",
      },
      leaseStatusOptions,
      detailData: {},
      active: -1,
      show: false,
      textarea: "",
      checkList: ["1", "2"],

      arr: [
        { id: 0, name: "待广告挂牌" },
        { id: 1, name: "待推荐租客" },
        { id: 2, name: "待上传租约" },
        { id: 3, name: "出租成功" },
      ],
      sizeForm: {},
      objFour: {
        show: false,
        title: "请填写跳过理由",
        width: "647px",
      },
      stepData: {},
    };
  },
  computed: {
    stepArr() {
      const initArr = [
        { id: 0, name: "待广告挂牌" },
        { id: 1, name: "待推荐租客" },
        { id: 2, name: "待上传租约" },
        { id: 3, name: this.$store.state.app.step3Title },
      ];
      if (this.detailData.step > 3) {
        return [
          ...initArr,
          { id: 4, name: "待确认租客搬离时间" },
          { id: 5, name: "待上传搬离清单" },
          { id: 6, name: "待业主确认" },
          { id: 7, name: "搬离成功" },
        ];
      } else {
        return initArr;
      }
    },
  },
  watch: {
    active(newVal, oldVal) {
      if (newVal > 3 && this.stepArr.length === 4) {
        this.arr = [
          ...this.stepArr,
          { id: 4, name: "待确认租客搬离时间" },
          { id: 5, name: "待上传搬离清单" },
          { id: 6, name: "待业主确认" },
          { id: 7, name: "搬离成功" },
        ];
      }
    },
  },
  async created() {
    this.id = this.$route.query.id;
    await this.getDetail();
  },
  methods: {
    getAdImage(img) {
      this.step1Form.poster = img;
    },
    async getDetail() {
      var detailRes = await leaseDetail(this.id);
      // console.log("22222222222", detailRes);
      this.detailData = detailRes.data;
      this.jumpData.id = this.id;
      this.active = this.detailData.step - 1 || 0;
    },
    changeId(id) {
      // console.log("111111111", id);
      this.id = id;
      this.$route.query.id = id;
      this.getDetail();
    },
    async confirmDel() {
      var delRes = await leaseDel(this.id);
      if (delRes.code === 200) {
        this.$message({
          message: "操作成功！",
          type: "success",
        });
      }
      this.objMo.show = false;
      this.goBack();
    },
    jump(stepData) {
      this.objFour.show = true;
      this.stepData = stepData;
    },
    next(val) {
      if (val !== undefined) {
        this.active = val;
      } else {
        this.active++;
      }

      this.getDetail();
    },
    async confirmJump() {
      this.jumpData.jumpStep = this.active + 1;
      this.jumpData.stepName = this.stepData.stepName;
      this.jumpData.id = this.id;
      var jumpRes = await jump({ ...this.jumpData, ...this.stepData });
      if (jumpRes.code === 200) {
        this.jumpData.jumpNote = "";
        this.active++;
        this.objFour.show = false;
      }
      // await edit(this.stepData)
      this.getDetail();
    },
    goBack() {
      if (this.$route.query.isDetail) {
        this.$router.go(-1);
      } else {
        this.$router.push("/house/page");
      }
    },
    showDigo(val) {
      if (val) {
        this.objFour.show = val;
        return;
      }
      this.active = this.active * 1 + 1;
    },
  },
};
</script>

<style lang="scss" scoped>
.countFsColor {
  cursor: pointer;
}
.mpdalBody p {
  padding: 20px;
  text-align: center;
  font-size: 20px;
}
.myBnt {
  color: #5ac6b7;
  display: block;
  width: 100px;
  margin-left: 115px;
  margin-bottom: 20px;
  border: 0;
}
.divUl {
  margin: 0px auto 0 auto;
}
h5,
p {
  padding: 0;
  margin: 0;
}
.ulMy {
  flex-wrap: wrap;
  width: 166px;
  padding-left: 10px;
}
.ulMy li {
  width: 100%;
  display: flex;
  align-items: center;
  margin-bottom: 15px;
  height: 40px;
  line-height: 40px;
}
.ulMy li i {
  color: #6a6a6a;
  font-size: 13px;
  align-self: self-start;
  margin-top: 23px;
}
.ulMy li p {
  color: #6a6a6a;
  font-size: 13px;
}
.ulMy li h5 {
  font-size: 16px;
  color: #151515;
  margin-bottom: 10px;
}
.ulMy li div {
  background: #fff;
  margin-left: 0px;
  flex: 1;
  padding: 0px;
  box-sizing: border-box;
  border-radius: 2px;
  text-align: center;
  font-size: 12px;
}
.ulMy li em {
  color: #5ac6b7;
  margin-left: 3px;
}
.ulMy li dfn {
  color: #5ac6b7;
  margin-top: 3px;
  font-size: 12px;
  display: block;
  margin-top: 10px;
}
.ulMy li.not {
  color: #ccc;
}
.ulMy li.not h5 {
  font-size: 16px;
  color: #ccc;
  margin-bottom: 10px;
}
.ulMy li.not div {
  background: #fff;
  margin-left: 0px;
  flex: 1;
  padding: 0px;
  box-sizing: border-box;
  border-radius: 2px;
}
.ulMy li.not p {
  color: #ccc;
}
.overview-content {
  min-height: calc(100vh - 160px);
  background: #eee;
}
.myDigo h2 {
  background: #343436;
}
::v-deep .myDigo .el-dialog__footer {
  background: #e5e9ed;
  padding-top: 15px;
}
::v-deep .el-dialog.myDigo .el-dialog__body {
  padding: 0;
}
::v-deep .el-dialog.myDigo .el-dialog__header {
  display: none;
}
.el-dialog.myDigo h2 {
  height: 58px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-left: 39px;
  padding-right: 39px;
  color: #fff;
  font-size: 18px;
  padding-top: 0;
  margin-top: 0;
  overflow: hidden;
  font-weight: normal;
  font-family: "SourceHanSansSC-regular";
}
.el-dialog.myDigo h2 i {
  font-size: 26px;
  cursor: pointer;
}
::v-deep .el-dialog.myDigo .el-dialog__body {
  text-align: left;
}
.formDiv {
  padding-left: 39px;
  padding-right: 39px;
  background: #fff;
  overflow: hidden;
}
.divSE {
  text-align: center;
}
.divSE em {
  display: block;
}
.fileWD {
  font-size: 46px;
  color: #5ac6b7;
}
.titleDiv {
  background: #5ac6b7;
  padding-left: 20px;
  color: #fff;
  height: 60px;
  line-height: 60px;
  font-weight: 900;
}
.two {
  margin: 10px 0;
  font-size: 13px;
  padding-left: 10px;
  padding-right: 10px;
}
.overview-tabs {
  background: #6a6a6a !important;
}
.inputTop {
  display: flex;
  justify-content: space-between;
}
.el-upload__tip {
  display: inline-block;
}
.formdiv {
  width: calc(100% - 200px);
}
.p1 {
  font-size: 12px;
  color: #d0d0d0;
}
.addBntLease p {
  display: inline-block;
  width: 68px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  color: #5ac6b7;
  cursor: pointer;
  border: 1px solid #5ac6b7;
  border-radius: 3px;
  font-size: 14px;
  margin-right: 10px;
}
.ulLeaseBnt li {
  background: #f8fbfa;
  border-radius: 6px;
  margin-top: 10px;
  font-size: 12px;
  display: flex;
  box-sizing: border-box;
  padding: 20px;
  flex-wrap: wrap;
}
.ulLeaseBnt li div.left {
  color: #666;
  width: 110px;
  text-align: left;
}
.ulLeaseBnt li div.left p {
  margin-bottom: 10px;
}
.ulLeaseBnt li div.left p:nth-child(1) {
  color: #5ac6b7;
  font-size: 13px;
}
.ulLeaseBnt li div.right p i {
  display: block;
  margin-bottom: 8px;
}
.ulLeaseBnt li div.right dfn {
  margin-top: 20px;
  display: block;
  color: #5ac6b7;
}
.ulLeaseBnt li div.line {
  border-top: 1px solid #f0f0f0;
  display: block;
  width: 100%;
  margin-top: 13px;
  padding-top: 22px;
  padding-left: 110px;
  box-sizing: border-box;
}
.ulLeaseBnt li div.line dfn {
  margin-right: 10px;
  color: #5ac6b7;
}
.ulLeaseBnt li:last-child {
  margin-bottom: 20px;
}
.opdfn {
  position: absolute;
  right: -12px;
  top: 0px;
  z-index: 99;
}
.agg {
  padding-left: 8px !important;
  padding-right: 8px !important;
}
.addAgg {
  color: #5ac6b7;
}
.fromDivArr {
  margin-bottom: 10px;
  overflow: hidden;
}
.divZk {
  margin-bottom: 20px;
}
.divZk ul li {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
}
.divZk ul li {
  color: #101010;
  font-size: 12px;
  width: 100%;
}
.divZk ul li i {
  color: #b3b3b3;
  width: 50px;
  text-align: right;
  display: inline-block;
  margin-right: 10px;
}
.divZk ul li p {
  width: 33.3%;
  text-align: left;
}
.divZk ul.auto li {
  width: auto;
}
.divZk ul.auto li {
  flex-wrap: wrap;
}
.divZk ul.auto li p {
  display: block;
  width: 100%;
  margin-bottom: 10px;
}
.divZk ul.auto li p em {
  margin-right: 20px;
}
.divZk ul li span {
  color: #5ac6b7;
}
.pAll {
  font-size: 12px;
  color: #5ac6b7;
}
.pAll span {
  margin-right: 15px;
}
.pAll span i {
  margin-left: 15px;
}
</style>
